import { ref, reactive, type Ref, onMounted } from "vue";
import type { PaginationProps } from "@pureadmin/table";
import { getDeliverListApi } from "@/api/deliverApi";
export function useGoodsColumns(goodsSelectRef: Ref, listArr, selectValue) {
  const goodsSelectValue = ref("");
  const goodsColumns: TableColumnList = [
    {
      label: "发货单编号",
      prop: "orderNum",
      minWidth: 200
    },
    {
      label: "公司简称",
      prop: "corp.shortName"
    },
    {
      label: "发货日期",
      prop: "dispatchDate",
      minWidth: 200
    },
    {
      label: "状态",
      prop: "statusStr"
    }
  ];

  /** 分页配置 */
  const goodsPagination = reactive<PaginationProps>({
    pageSize: 10,
    currentPage: 1,
    layout: "prev, pager, next",
    total: 0,
    background: true
  });
  const goodsDataList = ref([]);
  async function onSearch() {
    const { result } = await getDeliverListApi();
    goodsDataList.value = result.list;
    goodsPagination.total = result.total;
  }
  /** 高亮当前选中行 */
  function goodsRowStyle({ row: { orderNum } }) {
    return {
      cursor: "pointer",
      background:
        orderNum === goodsSelectValue.value ? "var(--el-fill-color-light)" : ""
    };
  }
  /** 行点击 */
  function goodsOnRowClick(row, _column, _event, did) {
    selectValue[did - 1].goodsSelectValue = row.orderNum;
    goodsSelectRef.value.blur();
    listArr[did - 1].dispatchOrderGoodsId = row.dispatchOrderId;
  }
  onMounted(() => {
    onSearch();
  });
  return {
    goodsColumns,
    goodsPagination,
    goodsSelectValue,
    goodsDataList,
    goodsRowStyle,
    goodsOnRowClick
  };
}
